import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';
import {MessageService} from './public/service/message/message.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
  message: any;
  subscription: Subscription;

  constructor(private messageService: MessageService) {
    this.subscription = this.messageService.getMessage()
      .subscribe(message => {
        this.message = [];
        switch (message.severity) {
          case 'error':
            this.message.push({severity: message.severity, summary: '错误', detail: message.detail});
            break;
          case 'warn':
            this.message.push({severity: message.severity, summary: '警告', detail: message.detail});
            break;
          case 'info':
            this.message.push({severity: message.severity, summary: '提示', detail: message.detail});
            break;
          case 'success':
            this.message.push({severity: message.severity, summary: '成功', detail: message.detail});
            break;
        }


      });
  }

  ngOnInit() {
  }

  ngOnDestroy() {
    this.subscription.unsubscribe();
  }
}
